package test;

import benchmark.Benchmark;
import data.StringDataSetGenerator;
import implementation.sort.AbstractSorter;
import implementation.sort.QuickSort.*;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;


public class QuickReportMD {


    private static Benchmark benchmark;
    private static StringDataSetGenerator generator;

    public static void main(String[] args) {
        benchmark = new Benchmark();
        ArrayList<AbstractSorter> sorters = getSorterList();

        generator = new StringDataSetGenerator();
        Comparator comparator = generator.getComparator();
        ArrayList<Integer> nList = getNList();

        for (int i = 0; i < nList.size(); i++) {
            int n = nList.get(i);
            System.out.println("\nN° of words = " + n);
            List<String> wordList = generator.createFromFile("src/test/moby_dick.txt", n);
            for (AbstractSorter s : sorters) {
                printReport(s, comparator, wordList);
            }
        }
    }

    private static void printReport(AbstractSorter sorter, Comparator comparator, List<String> wordList) {
        ArrayList<String> wordListC = (ArrayList) ((ArrayList) wordList).clone();
        System.out.println("\t" + sorter.getType());

        long t0 = System.currentTimeMillis();
        sorter.sort(comparator, wordListC);
        long tf = System.currentTimeMillis();

        System.out.println("\t\t\tTime: " + (tf - t0));
        System.out.println("\t\t\tComparissons: " + benchmark.getComparisons());
        System.out.println("\t\t\tSwaps: " + benchmark.getSwaps());
    }


    public static ArrayList<Integer> getNList() {
        ArrayList<Integer> nList = new ArrayList<Integer>();
        nList.add(12500);
        nList.add(25000);
        nList.add(50000);
        nList.add(100000);
        return nList;
    }

    public static ArrayList<AbstractSorter> getSorterList() {
        ArrayList<AbstractSorter> sorters = new ArrayList<AbstractSorter>();
        QuickSorter quickSorter = new QuickSorter();
        QuickSortMedianOfThree medianOfThree = new QuickSortMedianOfThree();
        QuickSortNonRecursive nonRecursive = new QuickSortNonRecursive();
        QuickSortCutOff cutOff = new QuickSortCutOff();
        QuickSortThreeWayPartition threePartition = new QuickSortThreeWayPartition();

        cutOff.setM(7);

        quickSorter.addSorterListener(benchmark);
        medianOfThree.addSorterListener(benchmark);
        nonRecursive.addSorterListener(benchmark);
        cutOff.addSorterListener(benchmark);
        threePartition.addSorterListener(benchmark);

        sorters.add(quickSorter);
        sorters.add(medianOfThree);
        sorters.add(nonRecursive);
        sorters.add(cutOff);
        sorters.add(threePartition);
        return sorters;
    }
}

